using System.Collections;
using UnityEngine;

public class Enemy12 : TypeOfEnemy
{
	public void Init(int arrayNum)
	{
		arrayNumForAllObjectsInfo = arrayNum;
		SetEnemy();
		StopAllCoroutines();
		StartCoroutine(Motions());
		StartCoroutine(RefreshPosition());
		StartCoroutine(IE_Update());
		StartCoroutine(IE_DrawShadow());
		grabingWeaponID = 6;
		grabingWeaponID += GM.instance.appearedCountOfbossList[5] * 6;
		if (GM.instance.appearedCountOfbossList[5] < 4)
		{
			GM.instance.appearedCountOfbossList[5]++;
		}
		EquipGetOrDrop("Enemy", true, 1, grabingWeaponID);
		ChangeCharacterAnimType(GetKindOfWeaponNumber());
		SR_Helm.sprite = Sprites.instance.enemyHelmSpriteList[5];
	}

	private IEnumerator Motions()
	{
		Teleport();
		yield return new WaitForSeconds(1f);
		while (AllObjectsInfo.enemy[arrayNumForAllObjectsInfo].hp > 0f)
		{
			yield return new WaitForSeconds(0.2f);
			if (CheckAction())
			{
				continue;
			}
			if (freezingTime > 0f)
			{
				freezingTime -= 0.1f;
				continue;
			}
			LookAtThePlayer();
			if (Vector2.Distance(Player.instance.tf.position, AllObjectsInfo.enemy[arrayNumForAllObjectsInfo].pos) < 12f)
			{
				Teleport();
			}
			else if (Calc.IsVisibleCharacterOnScreen(tf.position))
			{
				kindOfMotion = 1;
				Attack();
			}
			else
			{
				Teleport();
			}
		}
	}

	public void Teleport()
	{
		BodyTrailSwtich(2f);
		tf.position = new Vector2(Random.Range(-20f, 20f) + Cam.instance.tf.position.x, Random.Range(15, 0));
		rb.position = new Vector2(Random.Range(-20f, 20f) + Cam.instance.tf.position.x, Random.Range(15, 0));
	}

	public override void Attack()
	{
		if (!(Player.instance.hp <= 0f))
		{
			at.Play(weaponAttack_NormalList[currentAttackNumber], -1, 0f);
		}
	}

	public void ShootArrow()
	{
		Vector2 pos = new Vector2(Player.instance.tf.position.x - 5f, 0f);
		Generator.instance.SpawnObj(20, pos, new float[3]
		{
			1f,
			AttackPower(),
			12f
		});
	}

	public override void Damaged(Vector2 attackedPos, AttackInfo attackInfo)
	{
		if (!(hp <= 0f))
		{
			Generator.instance.SpawnObj(9, new Vector2(TF_CenterBone.position.x, TF_CenterBone.position.y));
			hp -= attackInfo.power;
			AllObjectsInfo.enemy[arrayNumForAllObjectsInfo].hp = hp;
			Cam.instance.Shake(0.1f, 0.3f);
			if (attackInfo.power > 0)
			{
				GM.instance.IMG_EmenyHP.fillAmount = Calc.Percentage(hp, maxHP + maxHP * (float)LevelController.instance.level * 0.2f);
			}
			Audio.instance.PlayWeaponSFX(attackInfo.kindOfWeapon);
			ComboText.instance.AddCombo();
			GM.instance.SlowMotion(0.02f, (float)attackInfo.power * 0.0002f + 0.1f);
			if (hp <= 0f)
			{
				StartCoroutine(IE_Die(attackInfo.force));
			}
		}
	}

	private IEnumerator IE_Die(Vector2 forceVel)
	{
		COL_AttackZone.gameObject.SetActive(false);
		COL_HitBox.enabled = false;
		attackingNow = false;
		GO_Blood.SetActive(true);
		GO_Blood.transform.localScale = tf.localScale;
		yield return new WaitForSeconds(0.02f);
		at.Play("StickMan_Damaged", -1, 1f);
		EquipGetOrDrop("Enemy", false);
		AttackZoneColOn(false);
		ComboText.instance.AddScore(1000);
		Generator.instance.SpawnObj(19, tf.position);
		Audio.instance.sfx[Random.Range(30, 35)].Play();
		yield return new WaitForSeconds(0.02f);
		at.enabled = false;
		IKDynamicOn(true, forceVel);
		tf.localScale = new Vector3((!(tf.position.x > Player.instance.tf.position.x)) ? (0f - characterScale) : characterScale, characterScale, 1f);
		StartCoroutine(IE_DeActive());
	}
}
